﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;

using LEEAAttendanceControl.Web;
using LEEAAttendanceControl.Web.Services;

namespace LEEAAttendanceControl.Views
{
    public partial class WorkDays : Page
    {
        private CheckBox checkAllBox = null;

        public WorkDays()
        {
            InitializeComponent();
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            App myApp = (App)Application.Current;

            myApp.ClearEvents();
        }

        private void SelectAllCheckBox_Click(object sender, RoutedEventArgs e)
        {
            CheckBox selector = sender as CheckBox;

            if (checkAllBox == null)
            {
                checkAllBox = selector;
            }

            foreach (var item in DaysGrid.ItemsSource)
            {
                CheckBox check = DaysGrid.Columns.Last().GetCellContent(item) as CheckBox;

                if (check != null)
                {
                    if (selector.IsChecked.Value)
                    {
                        check.IsChecked = true;
                    }
                    else
                    {
                        check.IsChecked = false;
                    }
                }
            }
        }

        private void DaySelector_Click(object sender, RoutedEventArgs e)
        {
            CheckBox rowCheck = sender as CheckBox;

            if (!rowCheck.IsChecked.Value)
            {
                if (checkAllBox != null && checkAllBox.IsChecked.Value)
                {
                    checkAllBox.IsChecked = false;
                }
            }
        }

        private void ApplyButton_Click(object sender, RoutedEventArgs e)
        {

        }
    }
}
